<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Markdown 文档阅读</title>
    <!-- 更换 CDN 链接引入 marked 库 -->
    <script src="https://unpkg.com/marked@4.3.0/marked.min.js"></script>
    <!-- 引入 highlight.js 库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f4f4f4;
        }

        #markdown-content {
            max-width: 800px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>

<body>
    <div id="markdown-content"></div>
    <script>
        // 检查 marked 库是否加载成功
        if (typeof marked === 'undefined') {
            console.error('marked 库未成功加载，请检查引入的 CDN 链接或本地文件路径。');
        } else {
            // 使用 fetch API 加载本地 Markdown 文件
            fetch('TypeScript.md')
               .then(response => {
                    if (!response.ok) {
                        throw new Error(`HTTP error! status: ${response.status}`);
                    }
                    return response.text();
                })
               .then(markdownText => {
                    // 将 Markdown 文本转换为 HTML
                    const htmlContent = marked.parse(markdownText);
                    const markdownContentDiv = document.getElementById('markdown-content');
                    markdownContentDiv.innerHTML = htmlContent;

                    // 应用语法高亮
                    document.querySelectorAll('pre code').forEach((block) => {
                        hljs.highlightBlock(block);
                    });
                })
               .catch(error => console.error('加载 Markdown 文件时出错:', error));
        }
    </script>
</body>

</html>
